using System;
using ProdControls.Bridges;
using ProdControls.Interfaces;

namespace ProdControls
{
    /// <summary>
    ///   Provides mechanisms to work with Edit (or TextBox) controls
    /// </summary>
    public sealed class ProdEdit : BaseProdControl, IValue
    {
        #region Constructors

        /// <summary>
        ///   Initializes a new instance of the ProdTextBox class.
        /// </summary>
        /// <param name="prodWindow"> The ProdWindow that contains this control. </param>
        /// <param name="automationId"> The UI Automation element </param>
        public ProdEdit(ProdWindow prodWindow, string automationId)
            : base(prodWindow, automationId)
        {
        }

        /// <summary>
        ///   Initializes a new instance of the ProdTextBox class.
        /// </summary>
        /// <param name="prodWindow"> The ProdWindow that contains this control. </param>
        /// <param name="treePosition"> The index of this control in the parent windows UI control tree. </param>
        public ProdEdit(ProdWindow prodWindow, int treePosition)
            : base(prodWindow, treePosition)
        {
        }

        /// <summary>
        ///   Initializes a new instance of the ProdTextBox class.
        /// </summary>
        /// <param name="prodWindow"> The ProdWindow that contains this control. </param>
        /// <param name="controlHandle"> Window handle of the control </param>
        public ProdEdit(ProdWindow prodWindow, IntPtr controlHandle)
            : base(prodWindow, controlHandle)
        {
        }

        #endregion

        /// <summary>
        ///   Gets the number of characters.
        /// </summary>
        public int Length
        {
            get { return this.GetLengthHook(this); }
        }

        #region IValue Members

        /// <summary>
        ///   Gets or sets the text.
        /// </summary>
        /// <value> The text. </value>
        public string Value
        {
            get { return this.GetValueHook(this); }
            set { this.SetValueHook(this, value); }
        }

        bool IValue.IsReadOnly
        {
            get { return this.GetReadOnlyHook(this); }
        }

        #endregion

        /// <summary>
        ///   Appends text to a text input control
        /// </summary>
        /// <param name="text"> Text To Append </param>
        public void AppendText(string text)
        {
            this.AppendValueHook(this, text);
        }

        /// <summary>
        ///   Clears the edit control of text.
        /// </summary>
        public void Clear()
        {
            this.ClearValueHook(this);
        }

        /// <summary>
        ///   Inserts the text at the specified (zero-based) index.
        /// </summary>
        /// <param name="text"> The text to insert. </param>
        /// <param name="index"> The zero-based index. </param>
        public void InsertText(string text, int index)
        {
            this.InsertValueHook(this, text, index);
        }
    }
}